package shuzu

func Erfen(nums []int, target int) int {
	if len(nums) == 1 {
		if nums[0] == target {
			return 0
		}
	}
	a, b := 0, len(nums)-1
	for a <= b {
		if target == nums[a] {
			return a
		}
		if target == nums[b] {
			return b
		}
		a++
		b--
	}
	return -1
}

func Erfen2(nums []int, target int) int {
	a, b := 0, len(nums)-1
	for a <= b {
		mid := a + (b-a)>>2
		if nums[mid] < target {
			a = mid + 1
		} else if nums[mid] > target {
			b = mid - 1
		} else {
			return mid
		}
	}
	return -1
}
